package com.bjxst;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

/**将对象序列化到文件*/
/*Users是实体类*/
public class ObjectInputStreamObjectTypeDemo {
    public static void main(String[] args) {
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("d:/x3.txt"));
          //  ois.readObject(); 读取文件内容，返回Objects类型
            Users users = (Users)ois.readObject();//强制转为Users 类型
            System.out.println(users.getUserid()+"\t"+users.getUsername()+"\t"+users.getUserage());


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(ois != null) ois.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
